let _ = require('underscore');
let CommentsModel = require("../model/commentsModel");
/**
 * 插入
 */
function replyComments(options) {
	let comments = new CommentsModel({
		pid: options.pid,
		post_id : options.post_id,
		content: options.content,
		name: options.name,
		email: options.email,
		agent: options.agent,
		create_at: Date.now()
	});
	return comments.save();
}
/**
 * 查询所有评论
 * @param query
 * @param options
 * @returns {*}
 */
function findComments(query, options){
	return CommentsModel.paginate(query, options);
}
/**
 * 评论点赞
 * @param options
 * @returns {*}
 */
function postLikeComment(options){
	return CommentsModel.findOneAndUpdate({
		_id: options._id
	}, {$inc:{likes: 1}});
}

module.exports = {
	'replyComments': replyComments,
	'findComments': findComments,
	'postLikeComment': postLikeComment
};
